home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 5
/
Amiga Tools 5.iso
/
tools
/
wb-tools
/
noclick
/
noclick.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-09
|
5KB
|
321 lines
/*
** NoClick
**
** © 1996 by Timo C. Nentwig
** All Rights Reserved !
**
** Tcn@techbase.in-berlin.de
**
*/
/// #include
#include <devices/trackdisk.h>
#include <dos/dos.h>
#include <exec/types.h>
#include <libraries/commodities.h>
#include <proto/commodities.h>
#include <proto/exec.h>
#include <pragmas/commodities_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <stdio.h>
///
/// #define
#define PRG_VERSION "1.0"
#define PRG_TITLE "NoClick"
#define PRG_AUTHOR "Timo C. Nentwig"
#define PRG_YEAR "1996"
///
// Prototypes
STATIC VOID ProcessMsg (VOID);
STATIC BOOL AttachFilter (STRPTR onkey, ULONG user_event);
STATIC VOID __regargs DriveClick (BOOL On);
// Version
STATIC BYTE __ver[] = "$VER: " PRG_TITLE " " PRG_VERSION " " __AMIGADATE__;
// Externals
struct Library *CxBase;
struct MsgPort *broker_mp;
CxObj *broker;
ULONG cxsigflag;
BOOL fullheight;
/// main ()
VOID
main (UWORD argc, STRPTR *argv)
{
if (CxBase = OpenLibrary ("commodities.library", 37))
{
if (broker_mp = CreateMsgPort())
{
STRPTR *ttypes;
struct NewBroker newbroker =
{
NB_VERSION,
PRG_TITLE,
PRG_TITLE " " PRG_VERSION " © " PRG_YEAR " by " PRG_AUTHOR,
"Disable drive clicking",
NBU_UNIQUE | NBU_NOTIFY,
0, 0, 0, 0
};
newbroker.nb_Port = broker_mp;
cxsigflag = 1L << broker_mp->mp_SigBit;
ttypes = ArgArrayInit (argc, argv);
newbroker.nb_Pri = (BYTE) ArgInt (ttypes, "CX_PRIORITY", 0);
if (broker = CxBroker (&newbroker, NULL))
{
CxMsg *msg;
// Disable clicking
DriveClick (FALSE);
ActivateCxObj (broker, 1L);
ProcessMsg();
DeleteCxObjAll (broker);
while (msg = (CxMsg *) GetMsg (broker_mp)) // Empty the port of all CxMsgs
ReplyMsg ((struct Message *) msg);
}
DeletePort (broker_mp);
}
ArgArrayDone();
CloseLibrary (CxBase);
}
else
{
printf ("ERROR: Couldn't open commodities.library v37+\n");
}
}
///
/// ProcessMsg ()
/*
* FROM /rkm/libs/commodities/hotkey.c
*
* FUNCTION Process commodity messages.
*
* NOTE
*
* EXAMPLE ProcessMsg ();
*
*/
STATIC VOID
ProcessMsg (VOID)
{
CxMsg *msg;
ULONG sigrcvd;
ULONG msgid;
ULONG msgtype;
LONG returnvalue = 1L;
while (returnvalue)
{
sigrcvd = Wait (SIGBREAKF_CTRL_C | cxsigflag);
while (msg = (CxMsg *) GetMsg (broker_mp))
{
msgid = CxMsgID (msg);
msgtype = CxMsgType (msg);
ReplyMsg ((struct Message *) msg);
switch (msgtype)
{
case CXM_COMMAND:
switch (msgid)
{
case CXCMD_DISABLE:
ActivateCxObj (broker, 0L);
break;
case CXCMD_ENABLE:
ActivateCxObj (broker, 1L);
break;
case CXCMD_KILL:
returnvalue = 0L;
break;
case CXCMD_UNIQUE:
returnvalue = 0L;
break;
}
break;
}
}
if (sigrcvd & SIGBREAKF_CTRL_C)
returnvalue = 0L;
}
// Enable clicking
DriveClick (TRUE);
}
///
/// AttachFilter ()
/*
* FROM /CloseWB/CloseWB.c
*
* FUNCTION Attach a filter.
*
* NOTE
*
* EXAMPLE AttachFilter (hotkey, EVT_HOTKEY);
*
*/
STATIC BOOL
AttachFilter (STRPTR onkey, ULONG user_event)
{
CxObj *filter;
CxObj *sender;
CxObj *translator;
if (filter = CxFilter (onkey))
{
AttachCxObj (broker, filter);
if (sender = CxSender (broker_mp, user_event))
{
AttachCxObj (filter, sender);
if (translator = CxTranslate (NULL))
{
AttachCxObj (filter, translator);
if ( ! (CxObjError (filter)))
return (TRUE);
}
}
}
return (FALSE);
}
///
/// DriveClick ()
/*
* FROM /yak/wbstartup/clickdrive.c
*
* FUNCTION Enable or disable drive clicking
*
* NOTE TRUE = drive clicking off
* FALSE = drive clicking on
*
* EXAMPLE DriveClick (TRUE);
*
*/
STATIC VOID __regargs
DriveClick (BOOL On)
{
struct IOExtTD *td;
struct MsgPort *po;
struct TDU_PublicUnit *tpu;
REGISTER ULONG unit;
if (po = CreatePort (NULL, 0) )
{
for (unit = 0; unit < 4; unit++)
{
if (td = (struct IOExtTD *) CreateExtIO (po, sizeof (struct IOExtTD)) )
{
if ( ! (OpenDevice ("trackdisk.device", unit, (struct IORequest *) td, 0L)))
{
tpu = (struct TDU_PublicUnit *) td -> iotd_Req.io_Unit;
if (On)
tpu -> tdu_PubFlags &= ~TDPF_NOCLICK; // Keep on clicking !
else
tpu -> tdu_PubFlags |= TDPF_NOCLICK; // Stop clicking !
CloseDevice ( (struct IORequest *) td);
}
DeleteExtIO ( (struct IORequest *) td);
}
}
DeletePort (po);
}
}
///